package lesson.Client;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ClientDemo1_1 {
    public static void main(String[] args) throws IOException {
        //1.找码头
        DatagramSocket datagramSocket = new DatagramSocket(10000);

        //2.创建一个新的箱子
        byte [] b = new byte[1024];
        DatagramPacket dp = new DatagramPacket(b,b.length);

        //3.接收礼物
        System.out.println("----------接收前");
        datagramSocket.receive(dp);
        System.out.println("----------接收后");
        //4.获取礼物
        byte [] bytes = dp.getData();
        String s = new String(bytes,0,dp.getLength());
        System.out.println(s);

        datagramSocket.close();
    }
}
